package com.example.ffepeg.ffeAdder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {
        String ssmlString = "<speak>欢迎来到英雄联盟<break time='500ms'/>,德玛西亚<break time='400ms'/>,昂扬不灭<break time='500ms'/>,正在待命</speak>";
        String ssmStr = "<speak>噫吁嚱，危乎高哉！蜀道之难，难于上青天！蚕丛及鱼凫，开国何茫然！尔来四万八千岁，不与秦塞通人烟。西当太白有鸟道，可以横绝峨眉巅。地崩山摧壮士死，然后天梯石栈相钩连。上有六龙回日之高标，下有冲波逆折之回川。黄鹤之飞尚不得过，猿猱欲度愁攀援。</speak>";
/*        List<String> list = extractedPart1(ssmStr);
        System.err.println(list);*/

      /*  List<Integer> list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7);
        List<Integer> listK = Arrays.asList();

        for (Integer value : list) {
            if (listK.contains(value)) {
                System.out.println("数据1: " + value);
            }else {
                System.out.println("数据2: " + value);
            }
        }*/

/*

        String df = "欢迎来到英雄联盟<break time='500ms'/>";
        Integer time = StringToTime(df);
*/


/*        String string = removeSpeakAndBreakTags(ssmlString);
        System.out.println(string);


        List<String> listext = listext(string);
        System.out.println(listext);

        for (String phrase : listext){
            if (phrase.length() > 0) {
                char c = phrase.charAt(phrase.length() - 1);
                System.out.println(c);
            }
        }*/
        List<Integer> list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11,12,13,14,15,16,17,18,19,20);
        List<Integer> list1 = Arrays.asList(23,24,25,26,27,28,29,30);
        List<Integer> mergedList = new ArrayList<>(list); // 将第一个列表的所有元素添加进去
        mergedList.addAll(list1);

        List<List<Integer>> partitionedLists = new ArrayList<>();
        final int SIZE = 10;
        for (int i = 0; i < mergedList.size(); i += SIZE) {
            int end = Math.min(i + SIZE, mergedList.size());
            partitionedLists.add(mergedList.subList(i, end));
        }

        System.err.println(partitionedLists);
        // 打印结果
        for (List<Integer> sublist : partitionedLists) {
            System.out.println(sublist);
        }

    }


    //获取文字
    private static String removeSpeakAndBreakTags(String text) {
        String withoutSpeakTags = text.replaceAll("<speak>|</speak>", "");
        String cleanText = withoutSpeakTags.replaceAll("<break time='\\d+ms'/>", "");
        return cleanText;
    }

    private static List<String> listext (String text){
        String[] splitArray = text.split("[,?!]");
        List<String> resultList = new ArrayList<>(Arrays.asList(splitArray));
        return resultList;
    }


    private static List<String> extractedPart1(String ssmlString){
        List<String> extractedParts = new ArrayList<>();
        // 去除<speak>标签
        if (ssmlString.startsWith("<speak>") && ssmlString.endsWith("</speak>")) {
            ssmlString = ssmlString.substring(7, ssmlString.length() - 8);
        }

        // 定义一个模式来匹配特定的文本加上<break time='xxxms'/>标签
        String patternString = "(.*?)(<break time='\\d+ms'/>)";
        Pattern pattern = Pattern.compile(patternString, Pattern.DOTALL);
        Matcher matcher = pattern.matcher(ssmlString);

        int lastEndIndex = 0;
        while (matcher.find()) {
            if (matcher.start() > lastEndIndex) {
                // 如果有未匹配的文本，在这里添加
                extractedParts.add(ssmlString.substring(lastEndIndex, matcher.start()).trim());
            }
            // 组合文本与break标签
            extractedParts.add(matcher.group().trim()); // 添加到列表中并去除可能的多余空白
            lastEndIndex = matcher.end();
        }

        // 检查是否还有剩余的文本未被处理（即最后一个<break>之后的文本）
        if (lastEndIndex < ssmlString.length()) {
            extractedParts.add(ssmlString.substring(lastEndIndex).trim());
        }
       return extractedParts;
    }

    private static Integer StringToTime(String text){
        Pattern pattern = Pattern.compile("(\\d+)ms");
        Matcher matcher = pattern.matcher(text);
        int number = 0;
        if (matcher.find()) {
            // 提取第一个匹配到的数字
            String numberStr = matcher.group(1);
            number = Integer.parseInt(numberStr);
            System.out.println("提取到的时间是: " + number);
        } else {
            System.out.println("没有找到匹配的时间值");
        }
        return number;
    }

}
